package com.huitone.smspfm.oldclient.asclient.send;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;

import com.bin.common.utils.FileUtils;
import com.huitone.smspfm.oldclient.core.FileReader3;
import com.huitone.smspfm.oldclient.logger.ExtLogger;

/**   
* @Title MtFileReader.java 
* @Package com.huitone.smspfm.oldclient.module.mt 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年4月12日 上午12:30:30 
* @version V1.0   
*/
public class MtFileReader extends FileReader3 {
	private final static ExtLogger logger = ExtLogger.create(MtFileReader.class);
	
	public StringBuffer readFile(String fileDir, String fileRegex) {
		
//		StringBuffer buffer = null
		File file = getFile2(fileDir, fileRegex);
//		if (file != null) {
//			buffer = FileUtils.read(file, "GBK");
//		}
		return read(file, "GBK");
//		return null;

	}

	public static void main(String[] args) {

		String fileDir = "d:\\smstest\\mt";
		String fileRegex = "\\d+_fromtcp_\\d{14}_.+_\\d+.xml";
		while(true) {
			MtFileReader mtFileReader = new MtFileReader();

			StringBuffer sb = mtFileReader.readFile(fileDir, fileRegex);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

//		createFile(fileDir,10001,30000);
	}

	public static  void createFile(String fileDir,int start ,int count) {
		String STR_FORMAT = "00000000000000";
		File file = new File(fileDir);
		for (int i = start; i < count; i++) {
			DecimalFormat df = new DecimalFormat(STR_FORMAT);
			String countStr = df.format(i);
			File newFile = new File(file.getAbsolutePath() + "/00_fromtcp_"+countStr+"_aaaaa_001.xml");
			try {
				newFile.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
}
